const W = require("../lib").JianliaoWrapper;
const Toolbox = require("../lib/toolbox");
const path = require("path");
const fs = require("fs");
W.loginByMailPass("hujimiya@ya.ru", "Jianliao65huji").then(async o => {
  // debugger
  let o_me = await o.jianliao.__getMe();
  /*
  await o.jianliao.sendMessageMarkdown("test api -- 不带附件的message",
    "5befcfab8ada969e341498f2",
    "5befd05dd82cb0a71ee77001",
  );*/

  (async function uploadOneFileAndSend() {
    let filepath = path.join(__dirname, "../tmp/1GB.001")
    // let o_stats = await Toolbox.getStats(filepath);

    let o_strike = await o.jianliao.getStrikeToken();
    let o_up = await W.uploadFile(
      filepath, o_strike.token, parseInt(1 * 1024 * 1024 * 1024 - 1024 * 25000), (full_path, parts_count, part_index) => {
        let f = full_path.replace(".", "_#_.");
        return `${f}.${parts_count}.${part_index}`
      }
    );
    let o_message = await o.jianliao.sendMessageMarkdown(`文件大下坡测试`,
      "5befcfab8ada969e341498f2",
      "5befd05dd82cb0a71ee77001",
      o_up.parts.map(e => {
        return {
          category: "file",
          data: {
            fileSize: e.data.fileSize,
            fileName: e.data.fileName,
            fileType: e.data.fileType,
            fileKey: e.data.fileKey
          }
        }
      })
    );
    debugger
  });

  (function testMessageMaxLength() {
    new Promise(async resolve => {
      let o_message = await o.jianliao.sendMessageMarkdown(
        require("randomstring").generate(50000),
        "5befcfab8ada969e341498f2",
        "5befd05dd82cb0a71ee77001",
      )
      debugger
    });
    /**@description 到五万都没有问题 暂时没有去测上限 */
  });

  (async function testBesideId() {
    let o_test = await o.jianliao.getMessageFilesByBesideId(
      '5bf01dd8350cbc9f1e16922c',
      '5befcfab8ada969e341498f2',
      '5befd05dd82cb0a71ee77001');
    debugger
  });
  (async function testSaveDir() {
    let o_test = await o.jianliao.safelyStoreDaily1905(
      '5befcfab8ada969e341498f2',
      '5befd05dd82cb0a71ee77001',
      path.join(__dirname, "../node_modules/_axios@0.18.0@axios/lib/defaults.js")
    );
    let o_beside = await o.jianliao.getMessageFilesByBesideId(
      o_test.data.message_id,
      '5befcfab8ada969e341498f2',
      '5befd05dd82cb0a71ee77001');
    debugger
  })();
  (function uploadOneDir() {
    o.jianliao.safelySendMessageToSaveDir(
      "5befcfab8ada969e341498f2",
      "5befd05dd82cb0a71ee77001",
      path.join(__dirname, "../node_modules/args/node_modules/chalk"), "ChalkChalkLa"
    ).then(o_up => {
      debugger
    });
    // debugger
  });


  // let o_saveFile = await o.jianliao.sendMessageToSaveFile(
  //   "5befcfab8ada969e341498f2",
  //   "5befd05dd82cb0a71ee77001",
  //   filepath,
  //   500,
  //   {o:"com"}
  // );
  // // debugger
  // W.getValidInstance("hujimiya@ya.ru", "Jianliao65huji").then(async try1 => {
  //   await new Promise(r => setTimeout(r, 1000));
  //   let try2 = await W.getValidInstance("hujimiya@ya.ru", "Jianliao65huji");
  //   console.log(try1.jianliao===try2.jianliao)
  //   debugger
  // })
  // debugger
  /*
  W.uploadStream(fs.createReadStream(filepath), o_stats.stats.size, "index.js",
    "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1NDI2Mjk3MDUsInN0b3JhZ2UiOiJzdHJpa2VyLWh6In0.hC06Fe259z1HTHiH1tvDVcr_b0seFiCVAsn-Xdz1a9U")
*/
  // 

})